/* MainView.h - The Main UI for iSpotter.
 *
 * Copyright (C) 2008 Yuuichi Teranishi
 *
 * This file is derived from Stumbler, a program developed by iphone-wireless
 * project.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * published by the Free Software Foundation.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; If not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import <UIKit/UIKit.h>
#import <UIKit/UITransitionView.h>
#import <UIKit/UIPreferencesTable.h>
#import <UIKit/UIPreferencesTextTableCell.h>
#import <UIKit/UIButtonBar.h>
#import <UIKit/UIApplication.h>
#import <UIKit/UITextView.h>
#import <UIKit/UISegmentedControl.h>
#import <UIKit/UISwitchControl.h>

#import "MSNetworksManager.h"
#import "LockyDB.h"
#import "WifiDB.h"
#import "SimpleWebView.h"
#import "LogBrowser.h"
#import "SiteBrowser.h"

#include "version.h"

#define CB_DETECT 0x01
#define CB_HISTORY 0x02
#define CB_LEARN 0x03
#define CB_WEB 0x04
#define CB_PREFS 0x05
#define CB_DATES 0x06

#define byte unsigned char

struct iSpotter_Preferences {
  // group 1:
  byte polling;
  byte ignore;    // distance measurement constant
  // group 2:
  byte zoom;
  byte tracking;  // Keep Tracking
  byte movedist;  // spot distance
  // group 3:
  byte direct;    // Allow direct remote access
  byte pengine;   // PlaceEngine compatible
  // since 1.1.0
  byte caching;   // Map caching
  // since 1.2.1
  byte wifi;      // Auto Wifi
};

extern struct iSpotter_Preferences preferences;

@interface MainView : UIView {
  CGRect frame;

  UINavigationBar  *navBar;
  UINavigationBar  *bottomBar;

  UITransitionView *transitionView;
  SimpleWebView *detectionBrowser;
  SimpleWebView *historyBrowser;
  UIWebView *messageArea;
  UIPreferencesTable *prefsTable;
  UIButtonBar *buttonBar;
  UINavigationItem   *navItem;

  UIPushButton *mapButton;
  UIPushButton *detectButton;

  UIAlertSheet *registerSheet;
  UIAlertSheet *alertSheet;
  MSNetworksManager *networksManager;
  LockyDB *db;
  WifiDB *wdb;
  NSObject *scanningLock;
  BOOL scanning;

  double x, y;
  int f;
  double lastX, lastY;
  int lastF;

  NSDate *historyDate;
  NSDate *selectedDate;
  id mapLauncher;
  int currentView;
  int currentBrowserPage;

  BOOL tracking;
  BOOL caching;

  SiteBrowser *siteBrowser;

  id _delegate;
  LogDB *_logdb;

  LogBrowser *logBrowser;

  NSTimer *scanTimer;
  NSTimer *progressTimer;

  BOOL historyBrowserInitialize;
  BOOL learnBrowserInitialize;
  BOOL isPreference;


  UIPreferencesTableCell *cells[10][10];
  UIPreferencesTableCell *groupcell[10];

  UISegmentedControl *pollingControl;
  UISwitchControl *wifiControl;

  UISegmentedControl *zoomControl;

  UISegmentedControl *distanceControl;
  UISwitchControl *ignoreControl;
  UISwitchControl *trackingControl;
  UISwitchControl *cachingControl;
  UISwitchControl *serverControl;
  UISwitchControl *directControl;
  UISwitchControl *pengineControl;

  NSArray *regAPs;
  Location *regLocation;
  int regFloor;

}

- (void)dealloc;
- (BOOL) scan;
- (NSString *)lineForRSSI:(int) rssi type:(int) type;
- (void)start;

//- (void)showButtons;
//- (void)hideButtons;
- (void)restartScanPolling;
- (SimpleWebView *)createDetectionBrowser;
- (SimpleWebView *)createHistoryBrowser;
- (SimpleWebView *)createLearnBrowser;
- (LogBrowser *)createLogBrowser;
- (SiteBrowser *)createSiteBrowser;

- (UIPreferencesTable *)createPrefPane;
- (int)getCurrentView;
- (NSArray *)buttonBarItems;
- (id)createButton:(NSString *)name;
- (UINavigationBar *)createNavBar;
- (UIButtonBar *)createButtonBar:(UIView *)view;
- (UITransitionView *)createTransitionView;
- (void)startScan;
- (void)scanThread;

- (void) simpleWebView:(SimpleWebView *)view loadFinished:(NSURL*)url;
- (void)addSite:(NSString *)site permission:(BOOL)permission;

- (void)buttonBarItemTapped:(id)sender;
- (void)navigationBar:(UINavigationBar*)navbar buttonClicked:(int)button;
- (void) setMapLauncher:(id) launcher;
- (id)initWithFrame:(CGRect)frame delegate:(id)delegate logDB:(LogDB *) logdb;


extern NSString *kUIButtonBarButtonAction;
extern NSString *kUIButtonBarButtonInfo;
extern NSString *kUIButtonBarButtonInfoOffset;
extern NSString *kUIButtonBarButtonSelectedInfo;
extern NSString *kUIButtonBarButtonStyle;
extern NSString *kUIButtonBarButtonTag;
extern NSString *kUIButtonBarButtonTarget;
extern NSString *kUIButtonBarButtonTitle;
extern NSString *kUIButtonBarButtonTitleVerticalHeight;
extern NSString *kUIButtonBarButtonTitleWidth;
extern NSString *kUIButtonBarButtonType;

@end

